package edu.nf.api.controller.shopping;

import com.google.gson.Gson;
import edu.nf.api.controller.BaseController;
import edu.nf.meituan.dao.user.ShoppingDAO;
import edu.nf.meituan.dao.user.impl.ShopPingDAOImpl;
import edu.nf.meituan.model.order.user.UserShopPing;
import edu.nf.meituan.model.user.Shopping;
import org.nf.web.annotation.RequestMapping;
import org.nf.web.annotation.RequestParam;
import org.nf.web.servlet.View;
import org.nf.web.servlet.view.JsonView;

import java.util.List;

/**
 * @Date 2023/6/19
 * @Author zgm
 * 购物车
 */
public class ShopPingController extends BaseController {
    @RequestMapping("/user/ShopPing/add")
    public View addShopPing(@RequestParam("json") String json){
        Shopping shopping = new Gson().fromJson(json, Shopping.class);
        ShoppingDAO dao = new ShopPingDAOImpl();
        int i = dao.addShopPing(shopping);
        return new JsonView(i);
    }
    @RequestMapping("/user/ShopPing/query")
    public View queryShopPing(@RequestParam("uId") int uid,
                              @RequestParam("shopId") int shopId){

        ShoppingDAO dao = new ShopPingDAOImpl();
        List<UserShopPing> list = dao.listShopping(uid,shopId);
        return new JsonView(list);
    }
    @RequestMapping("/user/ShopPing/update")
    public View updateShopPing(@RequestParam("uId") int uid,
                               @RequestParam("shopId") int shopId){
        ShoppingDAO dao = new ShopPingDAOImpl();
        int row = dao.updateShopPing(uid, shopId);
        return new JsonView(row);
    }

}
